package com.infonam.data.source.model;

import java.util.Date;
import java.util.LinkedList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

@Entity
@Table(name="rental" , catalog="sakila")
public class Rental {
	@Id
	@GeneratedValue(strategy=GenerationType.IDENTITY)
	@Column(name="rental_id",unique=true,nullable=false)
	private int rental_id;
	@Temporal(TemporalType.DATE)
	@Column(name="rental_date",nullable=false)
	private Date rental_date;
	@ManyToOne(fetch=FetchType.LAZY)
	@Cascade({CascadeType.SAVE_UPDATE})
	@JoinColumn(name="inventory_id", nullable=false)
	private Inventory inventory_id;
	@ManyToOne(fetch=FetchType.LAZY)
	@JoinColumn(name="customer_id",nullable=false)
	private Customer customer_id;
	@Temporal(TemporalType.DATE)
	@Cascade({CascadeType.SAVE_UPDATE})
	@Column(name="return_date", nullable=false)
	private Date return_date;
	@ManyToOne(fetch=FetchType.LAZY)
	@Cascade({CascadeType.ALL})
	@JoinColumn(name="staff_id", nullable=false)
	private Staff staff_id;
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name="last_update",nullable=false,columnDefinition="TIMESTAMP default CURRENT_TIMESTAMP on update TIMESTAMP")
	private Date last_update;
	@OneToMany(fetch=FetchType.LAZY, mappedBy="rental")
	private List<Payment> paymentList = new LinkedList<Payment>();
	public int getRental_id() {
		return rental_id;
	}
	public void setRental_id(int rental_id) {
		this.rental_id = rental_id;
	}
	public Date getRental_date() {
		return rental_date;
	}
	public void setRental_date(Date rental_date) {
		this.rental_date = rental_date;
	}
	public Inventory getInventory_id() {
		return inventory_id;
	}
	public void setInventory_id(Inventory inventory_id) {
		this.inventory_id = inventory_id;
	}
	public Customer getCustomer_id() {
		return customer_id;
	}
	public void setCustomer_id(Customer customer_id) {
		this.customer_id = customer_id;
	}
	public Date getReturn_date() {
		return return_date;
	}
	public void setReturn_date(Date return_date) {
		this.return_date = return_date;
	}
	public Staff getStaff_id() {
		return staff_id;
	}
	public void setStaff_id(Staff staff_id) {
		this.staff_id = staff_id;
	}
	public Date getLast_update() {
		return last_update;
	}
	public void setLast_update(Date last_update) {
		this.last_update = last_update;
	}
	public List<Payment> getPaymentList() {
		return paymentList;
	}
	public void setPaymentList(List<Payment> paymentList) {
		this.paymentList = paymentList;
	}

}
